package com.ygxsk.carhome.ui.care;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.afollestad.materialdialogs.MaterialDialog;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.ColorUtils;
import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.NetworkUtils;
import com.blankj.utilcode.util.ObjectUtils;
import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.listener.OnItemChildClickListener;
import com.chad.library.adapter.base.listener.OnItemClickListener;
import com.flyco.roundview.RoundTextView;
import com.gyf.immersionbar.ImmersionBar;
import com.lxj.xpopup.core.BasePopupView;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;
import com.trello.rxlifecycle4.android.ActivityEvent;
import com.ygxsk.carhome.R;
import com.ygxsk.carhome.constant.ConstantApi;
import com.ygxsk.carhome.constant.ConstantSign;
import com.ygxsk.carhome.constant.ExtraKey;
import com.ygxsk.carhome.constant.ExtraValue;
import com.ygxsk.carhome.enumwrap.CallHistoryBusinessType;
import com.ygxsk.carhome.enumwrap.CouponAuditPermissions;
import com.ygxsk.carhome.enumwrap.CouponAuditStatus;
import com.ygxsk.carhome.event.EventCardMain;
import com.ygxsk.carhome.listener.Delivery;
import com.ygxsk.carhome.listener.DoSomeThingListener;
import com.ygxsk.carhome.listener.ErrorParentExtraSingle;
import com.ygxsk.carhome.response.CouponCustomerVo;
import com.ygxsk.carhome.response.CouponCustomerVoCopy;
import com.ygxsk.carhome.response.CouponPackedInfoDetail;
import com.ygxsk.carhome.retrofit.AddLogUpLoadInfo;
import com.ygxsk.carhome.retrofit.ApiException;
import com.ygxsk.carhome.retrofit.ApiRequestSubListener;
import com.ygxsk.carhome.retrofit.ApiService;
import com.ygxsk.carhome.retrofit.ErrorConsumer;
import com.ygxsk.carhome.retrofit.NetworkManager;
import com.ygxsk.carhome.retrofit.ResponseTransformer;
import com.ygxsk.carhome.ui.ErrorActivity;
import com.ygxsk.carhome.ui.adapter.CardCouponPackAdapter;
import com.ygxsk.carhome.utils.CommUtils;
import com.ygxsk.carhome.utils.StringCodeUtils;
import com.ygxsk.carhome.views.FJEditTextCountPublishTooSmall;
import com.ygxsk.integrated.retrofit.Parameterkey;

import org.greenrobot.eventbus.EventBus;

import java.util.ArrayList;
import java.util.HashMap;

import butterknife.BindView;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Consumer;
import okhttp3.MediaType;
import okhttp3.RequestBody;

/*
 * @Author:itchenqi175@163.com
 * @Time:2024/3/1  19:40
 * @Description:
 */
public class CardCouponPackDetailActivity extends ErrorActivity implements ErrorParentExtraSingle {

    @BindView(R.id.refreshlayoutincouponpack)
    SmartRefreshLayout refreshLayoutInCouponPack;

    @BindView(R.id.recyclerviewinincouponpack)
    RecyclerView recyclerViewInCouponPack;

    //审核礼包的审核
    @BindView(R.id.roundbuttonauditcouponpack)
    RoundTextView roundButtonAuditCouponPack;


    //携带过来的一条数据目的是为了获取优惠礼包的详情；
    private CouponCustomerVoCopy extra_couponCustomerVoCopy;

    private ArrayList<CouponCustomerVo> mDataResources = new ArrayList<>();

    //列表适配器
    private CardCouponPackAdapter cardCouponPackAdapter;

    //优惠礼包的名称
    private TextView textViewPack_name;

    //优惠礼包的使用规则
    private TextView textViewPack_rule;

    //审核状态
    private TextView textViewCouponPackStatusPack;

    //客户领取人姓名
    private TextView textViewEditViewNameSmartPack;
    //客户手机号
    private TextView textViewEditViewPhoneDetaiPack;
    //发放人
    private TextView textViewPushpersonPack;
    //发放时间
    private TextView textViewPushTimePack;
    //发放原因
    private TextView textViewPushReasonPack;

    //审核人的外侧包裹布局
    private LinearLayout linearLayoutAuditContentPack;
    //审核人姓名
    private TextView textViewEdistPersonPack;
    //审核时间
    private TextView textViewEdistTimePack;
    //审核备注
    private TextView textviewdistremarkpack;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mActivityInstance = this;

        processExtraData();

        initloading();

        initViews();

        gainDatas();

    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_card_coupon_pack_detail;
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();

        ImmersionBar.with(this)//
                .titleBar(R.id.toolbarygxskout)
                .fitsSystemWindows(true)//解决状态栏和布局重叠问题，任选其一，默认为false，当为true时一定要指定statusBarColor()，不然状态栏为透明色，还有一些重载方法
                //.statusBarColor(R.color.colorPrimary)//
                //.navigationBarColor(R.color.colorPrimary)//
                //.keyboardEnable(true)
                .init();

    }

    @Override
    protected void initToolBar(ToolbarHelper toolbarHelper) {

        toolbarHelper.setTitle(getString(R.string.title_coupon_pack_detail));

        toolbarHelper.setVersionName(true, AppUtils.getAppVersionName());
        toolbarHelper.setLayoutLeft(true, R.drawable.backicon, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                methodBack();
            }
        });

        toolbarHelper.setLayoutClose(false, "", null);

        //右侧是【编辑】
        toolbarHelper.setLayoutRight(false, 0, "", null);

//        toolbarHelper.setLayoutRight(true, 1, getString(R.string.title_cardverifi_right), new ClickUtils.OnDebouncingClickListener() {
//            @Override
//            public void onDebouncingClick(View v) {
//                //携带信息跳转到【编辑-提交】页面；
//                Bundle extra_bundle = new Bundle();
//                //携带是 客户关怀 过去的 到卡券核销列表
//                extra_bundle.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, ExtraValue.VALUE_JUMP_FORM_CARD_MAIN_ACTIVITY);
//                ActivityUtils.startActivity(extra_bundle, CardDistHistoryActivity.class);
//            }
//        });

    }

    @Override
    protected void onClickNodata(View v) {

        gainDatas();

    }

    @Override
    protected void initViews() {

//        recyclerViewInCouponPack.setLayoutManager(new MyLinearLayoutManager(this));
        recyclerViewInCouponPack.setLayoutManager(new GridLayoutManager(this, 3));

        cardCouponPackAdapter = new CardCouponPackAdapter(R.layout.cardcouponpackadapter, mDataResources);

        cardCouponPackAdapter.removeAllHeaderView();
        cardCouponPackAdapter.removeAllFooterView();

        cardCouponPackAdapter.addHeaderView(getHeaderView(recyclerViewInCouponPack));
        cardCouponPackAdapter.addFooterView(getFooterView(recyclerViewInCouponPack));

        recyclerViewInCouponPack.setAdapter(cardCouponPackAdapter);

        cardCouponPackAdapter.notifyDataSetChanged();

        cardCouponPackAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {

                CouponCustomerVo couponCustomerVo = (CouponCustomerVo) adapter.getItem(position);
                method_click_item(couponCustomerVo);

            }
        });

        //点击条目内容
        cardCouponPackAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {

                CouponCustomerVo couponCustomerVo = (CouponCustomerVo) adapter.getItem(position);

                switch (view.getId()) {

                    case R.id.roundtextviewsingledetail: {

                        method_click_item(couponCustomerVo);

                        break;
                    }

                    default:
                        break;
                }

            }
        });

        if (refreshLayoutInCouponPack != null) {
            refreshLayoutInCouponPack.setOnRefreshListener(new OnRefreshListener() {
                @Override
                public void onRefresh(@NonNull RefreshLayout refreshLayout) {

                    refreshLayout.getLayout().post(new Runnable() {
                        @Override
                        public void run() {

                            gainDatas();

                            refreshLayout.finishRefresh();

                        }
                    });

                }
            });
        }


        if (roundButtonAuditCouponPack != null) {
            roundButtonAuditCouponPack.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    //和优惠券的 审核弹窗是一样的。
                    method_audit_dialog_customer();

                }
            });
        }

    }

    //【审核】的圆角按钮
    private void method_handler_roundButtonAudit() {

        //如果有审核权限 要判断审核的逻辑
        //设置审核按钮的显示或者隐藏逻辑
        //如果需要审核，那么审核按钮显示：
        //是否可以审核（权限）1是0否
        //private Integer isExamine;
        //        public enum CouponAuditStatus {//特别注意，【已核销】是我自己自定义的
//            "auditStatus": 0, //审核状态 0：待审核 1：审核通过 2：审核不通过
//            AUDITSTATUS_TO_BE_REVIEWED(0, "待审核"),
//            AUDITSTATUS_REVIEWED(1, "审核通过"),//已审核
//            AUDITSTATUS_REVIEWE_NOT_PASS(2, "审核不通过"),//审核不通过--即是【已驳回】的状态。
//            AUDITSTATUS_HAS_DIST(3, "已核销");//已核销-和其他的都不一样,不是后台给的，是我自己的人为自定义的。
        if (flag_jumpfrom_where == CouponAuditStatus.AUDITSTATUS_HAS_DIST.getIndex()//
                || flag_jumpfrom_where == CouponAuditStatus.AUDITSTATUS_REVIEWED.getIndex()) {//

            //【已核销】+【待审核】是必须的不展示图片。
            roundButtonAuditCouponPack.setVisibility(View.GONE);

        } else {

            int isExamine = extra_couponCustomerVoCopy.getIsExamine();

            //是否是大礼包类型的，大礼包类型。 "packType": 2, //1：优惠券； 2:礼包
//        int packType = extra_couponCustomerVoCopy.getPackType();

            if (isExamine == CouponAuditPermissions.TYPE_NO_EXAMINE.getIndex()) {

                roundButtonAuditCouponPack.setVisibility(View.GONE);

            } else if (isExamine == CouponAuditPermissions.TYPE_YES_EXAMINE.getIndex()) {

                roundButtonAuditCouponPack.setVisibility(View.VISIBLE);

            } else {

                roundButtonAuditCouponPack.setVisibility(View.GONE);

            }
        }

    }

    private void method_click_item(CouponCustomerVo _couponCustomerVo) {

        CouponCustomerVoCopy couponCustomerVoCopy = new CouponCustomerVoCopy();

        //调剂跳转到 单独的优惠券的详情。
        if (!ObjectUtils.isEmpty(_couponCustomerVo)) {

            couponCustomerVoCopy.setCouponId(_couponCustomerVo.getCouponId());
            couponCustomerVoCopy.setCouponCustomerId(_couponCustomerVo.getCouponCustomerId());
            couponCustomerVoCopy.setPackCustomerId(_couponCustomerVo.getPackCustomerId());
            couponCustomerVoCopy.setIsExamine(_couponCustomerVo.getIsExamine());

            //判断条目是优惠券还是优惠券大礼包的逻辑：
            Bundle extra_bundle = new Bundle();

            //这是从哪里来的 原始携带 入口的标志

            //extra_bundle.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, flag_jumpfrom_where);

            //如果是从礼包详情进入【优惠券详情】的，那么详情内是不可以有审核能力的。
            extra_bundle.putInt(ExtraKey.EXTRA_JUMPFROM_WHERE, ExtraValue.VALUE_JUMP_FORM_CARDCOUPONPACK_DETAIL_ACTIVITY);

            extra_bundle.putParcelable(ExtraKey.EXTRA_COUPONCUSTOMERVO_COPY, couponCustomerVoCopy);

            ActivityUtils.startActivity(extra_bundle, CardCouponDetailActivity.class);

        }

    }

    @Override
    protected void gainDatas() {

        if (NetworkUtils.isConnected()) {

            getServerDatas();

        } else {

            //是否有其他的执行逻辑？
            netWorkError();
        }

    }

    private void getServerDatas() {

        HashMap<String, Object> map = new HashMap<>();

        map.put(Parameterkey.shopInfoId, mSession.getShopInfoId());

        if (extra_couponCustomerVoCopy != null) {
            map.put(Parameterkey.packCustomerId, extra_couponCustomerVoCopy.getPackCustomerId());//状态
        }

//      map.put(Parameterkey.status, RepairStatusUpLoadType.STATE_HAS_DISPATCH.getIndex());//状态

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_COUPONPACKCUSTOMER_GETBYID);
        addLogUpLoadInfo.setUrlPath(ApiService.couponPackCustomer_getById_url);
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);
        addLogUpLoadInfo.setToastToUser(true);
        addLogUpLoadInfo.setHashMapParameter(map);

        //RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
        //MediaType.parse(ApiService.HEADER_JSON))

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
//                .couponPackCustomer_getById(String.valueOf(extra_couponCustomerVoCopy.getPackCustomerId()))
                .couponPackCustomer_getById(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
                .compose(CardCouponPackDetailActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<CouponPackedInfoDetail>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

                        methodNotSuccessData(what_method, serverCode, serverMessage);

                    }
                })).doOnSubscribe(new Consumer<Disposable>() {
                    @Override
                    public void accept(Disposable disposable) throws Throwable {

                        loadingGone();

                    }
                }).subscribe(new Consumer<CouponPackedInfoDetail>() {
                    @Override
                    public void accept(CouponPackedInfoDetail couponPackedInfoDetail) throws Throwable {

                        if (couponPackedInfoDetail != null) {

                            extra_couponCustomerVoCopy.setIsExamine(couponPackedInfoDetail.getIsExamine());
                            extra_couponCustomerVoCopy.setPackCustomerId(Integer.parseInt(couponPackedInfoDetail.getPackCustomerId()));

                            method_handler_success(couponPackedInfoDetail);
                            method_handler_roundButtonAudit();


                            //footer优惠礼包的使用规则
                            Delivery.getInstance().post(new Runnable() {
                                @Override
                                public void run() {

                                    if (textViewPack_name != null) {
                                        textViewPack_name.setText(couponPackedInfoDetail.getCouponName());
                                    }

                                    if (textViewPack_rule != null) {
                                        textViewPack_rule.setText(couponPackedInfoDetail.getCouponDetail());
                                    }


                                    //-------------------------------------------------------------------------
                                    //客户领取人姓名
                                    if (textViewEditViewNameSmartPack != null) {
                                        textViewEditViewNameSmartPack.setText(couponPackedInfoDetail.getTrueName());
                                    }

                                    //客户手机号
                                    if (textViewEditViewPhoneDetaiPack != null) {

                                        String phoneResult = couponPackedInfoDetail.getPhone();

                                        if (!TextUtils.isEmpty(phoneResult)) {

                                            textViewEditViewPhoneDetaiPack.setText(StringCodeUtils.mobileEncrypt(phoneResult));

                                            //设置点击事件
                                            textViewEditViewPhoneDetaiPack.setOnClickListener(new View.OnClickListener() {
                                                @Override
                                                public void onClick(View v) {

                                                    clickButton_toCallPhone(CardCouponPackDetailActivity.this, couponPackedInfoDetail.getPhone(), CallHistoryBusinessType.BUSINESSTYPE_9.getIndex());

                                                }
                                            });

                                        }

                                    }

                                    //发放人
                                    if (textViewPushpersonPack != null) {
                                        textViewPushpersonPack.setText(couponPackedInfoDetail.getCreateCustomerName());
                                    }
                                    //发放时间
                                    if (textViewPushTimePack != null) {
                                        textViewPushTimePack.setText(couponPackedInfoDetail.getCreateTime());
                                    }
                                    //发放原因
                                    if (textViewPushReasonPack != null) {
                                        textViewPushReasonPack.setText(couponPackedInfoDetail.getExplain());
                                    }

                                    // TODO: 2024/3/6 15:43 审核状态判断
                                    //审核状态:审核状态都是一直隐藏的
                                    if (textViewCouponPackStatusPack != null) {
                                        textViewCouponPackStatusPack.setText(couponPackedInfoDetail.getAuditStatusName());
                                    }

//                                     enum CouponAuditStatus {//特别注意，【已核销】是我自己自定义的
//                                        //"auditStatus": 0, //审核状态 0：待审核 1：审核通过 2：审核不通过
//                                        AUDITSTATUS_TO_BE_REVIEWED(0, "待审核"),
//                                        AUDITSTATUS_REVIEWED(1, "审核通过"),//已审核
//                                        AUDITSTATUS_REVIEWE_NOT_PASS(2, "审核不通过"),//审核不通过--即是【已驳回】的状态。
//                                        AUDITSTATUS_HAS_DIST(3, "已核销");//已核销-和其他的都不一样,不是后台给的，是我自己的人为自定义的。

//                                  "auditStatus": 0, //审核状态 0：待审核 1：审核通过 2：审核不通过
                                    int auditStatus = couponPackedInfoDetail.getAuditStatus();

                                    if (auditStatus == CouponAuditStatus.AUDITSTATUS_TO_BE_REVIEWED.getIndex()) {
                                        //待审核
                                        CommUtils.setViewGone(linearLayoutAuditContentPack);

                                    } else if (auditStatus == CouponAuditStatus.AUDITSTATUS_REVIEWE_NOT_PASS.getIndex()//审核未通过、审核驳回
                                            || auditStatus == CouponAuditStatus.AUDITSTATUS_REVIEWED.getIndex()) {//审核已通过
                                        //审核 驳回  审核不通过
                                        CommUtils.setViewVisible(linearLayoutAuditContentPack);

                                        //审核人姓名
                                        if (textViewEdistPersonPack != null) {
                                            textViewEdistPersonPack.setText(couponPackedInfoDetail.getAuditCustomerName());
                                        }
                                        //审核时间
                                        if (textViewEdistTimePack != null) {
                                            textViewEdistTimePack.setText(couponPackedInfoDetail.getAuditTime());
                                        }
                                        //审核备注
                                        if (textviewdistremarkpack != null) {
                                            textviewdistremarkpack.setText(couponPackedInfoDetail.getAuditRemark());
                                        }

                                    }


                                }
                            });

                        } else {

                            //

                        }

                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {

                        //页面报错；
                        function_apiException(apiException);


                    }
                });

    }

    @Override
    public void methodNotSuccessData(int what_method, String serverCode, String serverMessage) {
        super.methodNotSuccessData(what_method, serverCode, serverMessage);

        switch (what_method) {

            case ConstantApi.WHAT_COUPONPACKCUSTOMER_GETBYID: {

                if (mDataResources != null && mDataResources.isEmpty()) {

                    CommUtils.checkCurrently((ErrorActivity) mActivityInstance,//
                            serverCode,//
                            R.drawable.errorsear,//
                            serverMessage,//
                            getString(R.string.nulldatanow));

                }

                //这种审核按钮 是必须隐藏的
                CommUtils.setViewGone(roundButtonAuditCouponPack);


                break;
            }

            default:
                break;
        }

    }

    //页面成功的逻辑
    private void method_handler_success(CouponPackedInfoDetail _couponPackedInfoDetail) {

        if (mDataResources != null && !mDataResources.isEmpty()) {
            mDataResources.clear();
        }

        //添加布局内容
        ArrayList<CouponCustomerVo> datas = _couponPackedInfoDetail.getCouponCustomerList();

        if (datas != null && !datas.isEmpty()) {

            if (mDataResources != null) {
                mDataResources.addAll(datas);
            }

        } else {

            //也是遮盖逻辑
            fillNullDataView(StringUtils.getString(R.string.nulldatanow), R.drawable.errorsear);

        }

        if (cardCouponPackAdapter != null) {
            cardCouponPackAdapter.notifyDataSetChanged();
        }

        //重新处理一次审核的按钮判断？

    }

    //添加一个图片的header逻辑
    private View getHeaderView(RecyclerView _recyclerViewWork) {

        View workHeader;

        //2021年12月28日14:54:12 发现是崩溃的日志内容：
        // java.lang.NullPointerException: Attempt to invoke virtual method
        // 'android.view.ViewParent androidx.recyclerview.widget.RecyclerView.getParent()' on a null object reference
        if ((_recyclerViewWork != null) && (_recyclerViewWork.getParent() != null)) {
            workHeader = LayoutInflater.from(CardCouponPackDetailActivity.this).inflate(//
                    R.layout.coupon_pack_header, //
                    (ViewGroup) _recyclerViewWork.getParent(),//
                    false);//
        } else {
            workHeader = LayoutInflater.from(CardCouponPackDetailActivity.this).inflate(R.layout.coupon_pack_header, null);
        }

        //底部是圆角布局内侧

        return workHeader;
    }

    //有一个footerview
    //底部结算逻辑
    private View getFooterView(RecyclerView _recyclerViewWork) {

        View couponFooter;

        //2021年12月28日14:54:12 发现是崩溃的日志内容：
        // java.lang.NullPointerException: Attempt to invoke virtual method
        // 'android.view.ViewParent androidx.recyclerview.widget.RecyclerView.getParent()' on a null object reference

        if ((_recyclerViewWork != null) && (_recyclerViewWork.getParent() != null)) {
            couponFooter = LayoutInflater.from(CardCouponPackDetailActivity.this).inflate(//
                    R.layout.coupon_pack_footer, //
                    (ViewGroup) _recyclerViewWork.getParent(),//
                    false);//
        } else {
            couponFooter = LayoutInflater.from(CardCouponPackDetailActivity.this).inflate(R.layout.coupon_pack_footer, null);
        }

        //底部是圆角布局内侧
        textViewPack_name = (TextView) couponFooter.findViewById(R.id.textviewpack_name);
        textViewPack_rule = (TextView) couponFooter.findViewById(R.id.textviewpack_rule);

        //审核状态
        textViewCouponPackStatusPack = (TextView) couponFooter.findViewById(R.id.textviewcouponpackstatuspack);
        //客户领取人姓名
        textViewEditViewNameSmartPack = (TextView) couponFooter.findViewById(R.id.textvieweditviewnamesmartpack);
        //客户手机号
        textViewEditViewPhoneDetaiPack = (TextView) couponFooter.findViewById(R.id.textvieweditviewphonedetaipack);
        //发放人
        textViewPushpersonPack = (TextView) couponFooter.findViewById(R.id.textviewepushpersonpack);
        //发放时间
        textViewPushTimePack = (TextView) couponFooter.findViewById(R.id.textviewepushtimepack);
        //发放原因
        textViewPushReasonPack = (TextView) couponFooter.findViewById(R.id.textviewepushreasonpack);

        //审核人
        linearLayoutAuditContentPack = (LinearLayout) couponFooter.findViewById(R.id.linearlayoutauditcontentpack);
        //审核人姓名
        textViewEdistPersonPack = (TextView) couponFooter.findViewById(R.id.textviewedistpersonpack);
        //审核时间
        textViewEdistTimePack = (TextView) couponFooter.findViewById(R.id.textviewedisttimepack);
        //审核备注
        textviewdistremarkpack = (TextView) couponFooter.findViewById(R.id.textviewdistremarkpack);


        //底部五分之一的高度撑起
        TextView textviewPack_help_heig = (TextView) couponFooter.findViewById(R.id.textviewpack_help_heig);
        CommUtils.methodHelpView5(textviewPack_help_heig);


        return couponFooter;
    }


    @Override
    protected void methodBack() {

        methodBackFinish();

    }

    @Override
    public void processExtraData() {

        //use the data received here
        Bundle bundle = this.getIntent().getExtras();

        if (bundle != null) {

//          LogUtils.d(ConstantSign.LOGCAT_NOMAL + extra_jumpfrom_where);

            flag_jumpfrom_where = bundle.getInt(ExtraKey.EXTRA_JUMPFROM_WHERE);

            extra_couponCustomerVoCopy = bundle.getParcelable(ExtraKey.EXTRA_COUPONCUSTOMERVO_COPY);

            LogUtils.json(ConstantSign.LOGCAT_NOMAL, extra_couponCustomerVoCopy);

        }

    }

    //----------------------------------------------------------------------------------------------------------
    //审核通过是1 审核不通过是0；
    private int button_passOrRefuse = -1;
    private String editViewContentAudit = "";
    private MaterialDialog materialDialogCustomView;
    private BasePopupView mAlertBasePopupView;

    //确认的弹窗，因为底部有一个弹窗，不用这个弹窗会造成确认按钮无法点击
//    private BasePopupView popupViewConfirm;

    //审核逻辑布局
    private void method_audit_dialog_customer() {

        //弹窗布局
        View viewCard = View.inflate(mActivityInstance, R.layout.cardcouponauditdialog, null);

        if (viewCard != null) {

//            RoundTextView textViewAuditPass = (RoundTextView) viewCard.findViewById(R.id.textviewauditpass);
//            RoundTextView textViewAuditRefuse = (RoundTextView) viewCard.findViewById(R.id.textviewauditrefuse);

            RadioGroup radioGroupCheckAuditStatus = (RadioGroup) viewCard.findViewById(R.id.radioGroupCheckAuditStatus);
            RadioButton radiaoButtonChoosePass = (RadioButton) viewCard.findViewById(R.id.radiaoButtonChoosePass);
            RadioButton radiaoButtonChooseNotPass = (RadioButton) viewCard.findViewById(R.id.radiaoButtonChooseNotPass);

            FJEditTextCountPublishTooSmall editViewContentAuditReasonPopu = (FJEditTextCountPublishTooSmall) viewCard.findViewById(R.id.editviewcontentaudioreasonpopu);

            //取消 和 确定按钮
            RoundTextView textViewModifyChange = (RoundTextView) viewCard.findViewById(R.id.textviewmodifychange);
            RoundTextView textViewSubmit = (RoundTextView) viewCard.findViewById(R.id.textviewcomplete);

            //确定-审核通过
//            textViewAuditPass.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//
//                    //审核通过，可以不要原因.
//                    button_passOrRefuse = 1;
//
//                    //确定 -选中
//                    CommUtils.RoundTextViewButtonRed(textViewAuditPass);
//                    //驳回 不选中
//                    CommUtils.RoundTextViewButtonWhite(textViewAuditRefuse);
//
//                    LogUtils.d(ConstantSign.LOGCAT_NOMAL + "选中了【审核通过】");
//
//                }
//            });

            //驳回-审核不通过
//            textViewAuditRefuse.setOnClickListener(new View.OnClickListener() {
//                @Override
//                public void onClick(View v) {
//
//                    //审核通过，可以不要原因
//                    //审核不通过，必须填写原因
//                    button_passOrRefuse = 0;
//
//                    //确定 -不选中
//                    CommUtils.RoundTextViewButtonWhite(textViewAuditPass);
//                    //驳回 选中
//                    CommUtils.RoundTextViewButtonRed(textViewAuditRefuse);
//
//                    LogUtils.d(ConstantSign.LOGCAT_NOMAL + "选中了【审核驳回】");
//
//                }
//            });

            radioGroupCheckAuditStatus.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(RadioGroup group, int checkedId) {

                    if (checkedId == R.id.radiaoButtonChoosePass) {//审核 通过
                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "选中了【审核通过】");

                        //审核通过，可以不要原因.
                        button_passOrRefuse = 1;


                    } else if (checkedId == R.id.radiaoButtonChooseNotPass) {//审核驳回
                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "选中了【审核驳回】");

//                    //审核不通过，必须填写原因
                        button_passOrRefuse = 0;


                    }

                }
            });

            //取消按钮
            textViewModifyChange.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    button_passOrRefuse = 0;
                    editViewContentAuditReasonPopu.setText("");

                    //确定 按钮重置白色
//                    CommUtils.RoundTextViewButtonWhite(textViewAuditPass);
                    //驳回 按钮重置白色
//                    CommUtils.RoundTextViewButtonWhite(textViewAuditRefuse);

                    //将两个勾选都重置为空白
                    radiaoButtonChoosePass.setChecked(false);
                    radiaoButtonChooseNotPass.setChecked(false);

                    CommUtils.checkMaterialDialog(materialDialogCustomView);
                    CommUtils.checkBasePopupView(mAlertBasePopupView);

                }
            });

//            public enum CouponAuditStatus {
//                //"auditStatus": 0, //审核状态 0：待审核 1：审核通过 2：审核不通过
//                AUDITSTATUS_TO_BE_REVIEWED(0, "待审核"),
//                AUDITSTATUS_REVIEWED(1, "审核通过"),//已审核
//                AUDITSTATUS_REVIEWE_NOT_PASS(2, "审核不通过"),//审核不通过
//                AUDITSTATUS_HAS_DIST(3, "已核销");//已核销-和其他的都不一样,不是后台给的，是我自己的人为自定义的。

            //确定按钮-即 提交按钮。
            textViewSubmit.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    CommUtils.checkBasePopupView(mAlertBasePopupView);

                    editViewContentAudit = editViewContentAuditReasonPopu.getText().toString().trim();

                    //如果是审核通过，可以不用填写原因。
                    if (button_passOrRefuse == 1) {
                        //审核通过
                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "是审核通过，直接过去，不用填写原因");

                        //如果是【审核通过】那么立即关闭当前页面。
                        CommUtils.checkMaterialDialog(materialDialogCustomView);
                        method_gainVerifySubmitInfo_upLoad(extra_couponCustomerVoCopy.getPackCustomerId(), CouponAuditStatus.AUDITSTATUS_REVIEWED.getIndex(), editViewContentAudit);


                        //添加一个二次弹窗确认？
//                        popupViewConfirm = new XPopup.Builder(CardCouponPackDetailActivity.this)
//                                .isDestroyOnDismiss(true)
//                                .asConfirm(StringUtils.getString(R.string.clearaddorsubmitsuretitletips), //标题
//                                        StringUtils.getString(R.string.submit_consign_verify_message),//确定审核通过
//                                        StringUtils.getString(R.string.clearcachecancel), //取消按钮
//                                        StringUtils.getString(R.string.clearcachetitlesure),//确定按钮
//                                        new OnConfirmListener() {
//                                            @Override
//                                            public void onConfirm() {
//
//                                                //如果是【审核通过】那么立即关闭当前页面。
//                                                CommUtils.checkMaterialDialog(materialDialogCustomView);
//                                                method_gainVerifySubmitInfo_upLoad(extra_couponCustomerVoCopy.getCouponCustomerId(), CouponAuditStatus.AUDITSTATUS_REVIEWED.getIndex(), editViewContentAudit);
//
//                                            }
//                                        }, null, false);
//
//                        popupViewConfirm.show();

                    } else if (button_passOrRefuse == 0) {

//                        CommUtils.checkMaterialDialog(materialDialogCustomView);

                        //审核被驳回，必须填写原因。
                        editViewContentAudit = editViewContentAuditReasonPopu.getText().toString().trim();

                        if (TextUtils.isEmpty(editViewContentAudit)) {//审核原因-驳回原因是空的，那么。

                            CommUtils.checkBasePopupView(mAlertBasePopupView);

                            mAlertBasePopupView = CommUtils.method_showBasePopupViewSingle(CardCouponPackDetailActivity.this, //
                                    CardCouponPackDetailActivity.this,//
                                    CardCouponPackDetailActivity.this.getString(R.string.check_input_audit_reason));//

                            return;
                        }

                        CommUtils.checkMaterialDialog(materialDialogCustomView);
                        method_gainVerifySubmitInfo_upLoad(extra_couponCustomerVoCopy.getPackCustomerId(), CouponAuditStatus.AUDITSTATUS_REVIEWE_NOT_PASS.getIndex(), editViewContentAudit);

                    } else if (button_passOrRefuse == -1) {

//                        CommUtils.checkMaterialDialog(materialDialogCustomView);

                        LogUtils.d(ConstantSign.LOGCAT_NOMAL + "什么都没写？");

                        if (TextUtils.isEmpty(editViewContentAudit)) {//车辆类型 是必填项 2023-8-24 18:14:55

                            CommUtils.checkBasePopupView(mAlertBasePopupView);
                            mAlertBasePopupView = CommUtils.method_showBasePopupViewSingle(CardCouponPackDetailActivity.this, //
                                    CardCouponPackDetailActivity.this,//
                                    CardCouponPackDetailActivity.this.getString(R.string.check_choose_audit_button));//

                            return;
                        }

                    }

                }
            });

            //激发 弹窗弹出内容
            materialDialogCustomView = new MaterialDialog.Builder(CardCouponPackDetailActivity.this)
                    .customView(viewCard, false)
                    .contentColor(ColorUtils.getColor(R.color.buttonnomcolor))//
                    //.positiveText("确定")
                    .positiveColor(ColorUtils.getColor(R.color.dark))
                    //.negativeText("取消")
                    .canceledOnTouchOutside(false)
                    .show();

        }
    }

    //----------------------------------------------------------------------------------------------------------
    //优惠券的发放历史的审核状态；
    private void method_gainVerifySubmitInfo_upLoad(Integer _couponCustomerId, int _status_has_verify, String _auditRemark) {

//        CardAuditStatus {
//                    //审核状态 0：待审核 1：审核通过 2：审核不通过
//                    STATUS_NOT_VERIFY("0", "待审核"),
//                    STATUS_HAS_VERIFY("1", "审核通过"),
//                    STATUS_CANNOT_VERIFY("2", "审核不通过");
//        map.put(Parameterkey.couponId, _couponId);


        HashMap<String, Object> map = new HashMap<>();
        map.put(Parameterkey.packCustomerId, _couponCustomerId);//优惠券礼包的外侧id
        map.put(Parameterkey.auditStatus, _status_has_verify);//审核状态 审核状态：待审核 0
        map.put(Parameterkey.auditRemark, _auditRemark);//审核理由信息备注

        AddLogUpLoadInfo addLogUpLoadInfo = new AddLogUpLoadInfo();
        addLogUpLoadInfo.setActivity(mActivityInstance);
        addLogUpLoadInfo.setWhat(ConstantApi.WHAT_UPDATEAUDITSTATUS_URL);//请求数字标识
        addLogUpLoadInfo.setUrlPath(ApiService.updateAuditStatus_url);//url地址
        addLogUpLoadInfo.setRequestMethod(ConstantSign.REQUEST_METHOD_POST);//POST 或者 GET
        addLogUpLoadInfo.setToastToUser(true);//展示给用户的标志
        addLogUpLoadInfo.setAlertToUser(true);
        addLogUpLoadInfo.setHashMapParameter(map);

        NetworkManager.getInstance().initRetrofitRxJava()
                .create(ApiService.class)
                .updateAuditStatusById(RequestBody.create(JSON.toJSONString(map, SerializerFeature.PrettyFormat, SerializerFeature.WriteMapNullValue),
                        MediaType.parse(ApiService.HEADER_JSON)))
                .compose(CardCouponPackDetailActivity.this.bindUntilEvent(ActivityEvent.DESTROY))//
                .compose(new ResponseTransformer<>(addLogUpLoadInfo, new ApiRequestSubListener<String>() {
                    @Override
                    public void handlerSomeThingNotSuccessDataForItSelf(int what_method, String serverCode, String serverMessage) {
                        super.handlerSomeThingNotSuccessDataForItSelf(what_method, serverCode, serverMessage);

//                        if (!TextUtils.isEmpty(serverMessage)) {
//                            PopTip.show(serverMessage).iconWarning();
//                        }

                        function_response_20002(serverCode, serverMessage, addLogUpLoadInfo, true);

                    }
                })).subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String stringValue) throws Throwable {

                        //TipDialog.show(StringUtils.getString(R.string.add_submit_success), WaitDialog.TYPE.SUCCESS);

                        // TODO: 2024/2/29 19:39 主要的通知列表刷新和详情的刷新。
                        EventCardMain eventCardMain = new EventCardMain();
                        eventCardMain.setMessage(ExtraValue.EVENTBUS_EVENT_TO_REFRESH_CARD_MAIN_LIST);
                        EventBus.getDefault().post(eventCardMain);

                        methodSubmitSuccess(mActivityInstance, new DoSomeThingListener() {
                            @Override
                            public void doSomeThing() {

                                gainDatas();

                            }

                        });
                    }
                }, new ErrorConsumer() {

                    @Override
                    protected void error(ApiException apiException) {
                        function_apiException(apiException);
                    }
                });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mDataResources != null && !mDataResources.isEmpty()) {
            mDataResources.clear();
//            mDataResources = null;
        }

        if (cardCouponPackAdapter != null) {
            cardCouponPackAdapter.notifyDataSetChanged();
            cardCouponPackAdapter = null;
        }

        if (mDataResources != null) {
            mDataResources = null;
        }

        if (extra_couponCustomerVoCopy != null) {
            extra_couponCustomerVoCopy = null;
        }

        CommUtils.checkBasePopupView(mAlertBasePopupView);

        CommUtils.checkMaterialDialog(materialDialogCustomView);
    }
}